package com.galen.controller;

import java.util.Arrays;

/**
 * Created by 16978 on 2017/2/27.
 */
public class TestSuanFa {
    public static void main(String[] args) {
        Student s1 = new Student("anderson", 2);
        Student s2 = new Student("brown", 3);
        Student s3 = new Student("davis", 3);
        Student s4 = new Student("garcia", 4);
        Student s5 = new Student("harris", 1);
        Student s6 = new Student("Jackson", 3);
        Student s7 = new Student("Johnson", 4);
        Student s8 = new Student("Jones", 3);
        Student s9 = new Student("Martin", 1);
        Student s10 = new Student("Martinez", 2);
        Student s11 = new Student("Miller", 2);
        Student s12 = new Student("Moore", 1);
        Student s13 = new Student("Robinson", 2);
        Student s14 = new Student("Smith", 4);
        Student s15 = new Student("Taylor", 3);
        Student s16 = new Student("Thomas", 4);
        Student s17 = new Student("Thompson", 4);
        Student s18 = new Student("White", 2);
        Student s19 = new Student("Williams", 3);
        Student s20 = new Student("Wilson", 4);



        Student a[] = new Student[]{s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20};

        int k =1;
        System.out.println(a[++k].getName());
        System.out.println(a[k].getName());


        int n = a.length;
        int count [] = new int[n];
        for (int i =0;i<n;i++){
            count[a[i].getId() + 1]++;
        }

        System.out.println(Arrays.toString(count));
        for (int r=0;r<6;r++){
            count[r+1] += count[r];
        }
        System.out.println(Arrays.toString(count));

        Student aux [] = new Student[20];
        for (int i=0;i<n;i++){
            aux[count[a[i].getId()]++] = a[i];
        }

        for (int i =0 ;i<n;i++){
            a[i] = aux[i];
            System.out.println(a[i].getId()+"\t" + a[i].getName());
        }

    }
}

class Student {
    private String name;
    private int id;

    public Student(String name, int id) {
        this.name = name;
        this.id = id;
    }

    public String getName() {

        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
